package com.siwei.mes.entity;

import cn.dev33.satoken.stp.StpUtil;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.config.UidUtils;
import com.siwei.mes.enums.GenerateCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 试验台账取样(ExperimentSampleTake)实体类
 *
 * @author linzi
 * @since 2023-12-28 20:47:32
 */
@Data
@Accessors(chain = true)
@Table(name = "t_experiment_sample_take")
@ApiModel(value = "ExperimentSampleTake", description = "试验台账取样")
public class ExperimentSampleTake implements Serializable {
    private static final long serialVersionUID = -76119340899730515L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "试验台账取样主键ID", name = "id")
    @NotNull(groups = {UpdateGroup.class}, message = "id不能为空")
    private Long id;
    /**
     * 取样编号
     */
    @Column(name = "take_no")
    @ApiModelProperty(value = "取样编号", name = "takeNo")
    private String takeNo;
    /**
     * 试验台账id
     */
    @Column(name = "experiment_id")
    @ApiModelProperty(value = "试验台账id", name = "experimentId")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "试验台账id不能为空")
    private Long experimentId;
    /**
     * 小票id
     */
    @Column(name = "itemorder_id")
    @ApiModelProperty(value = "小票id", name = "itemorderId")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "小票id不能为空")
    private Long itemorderId;
    /**
     * 小票编号
     */
    @Column(name = "itemorder_no")
    @ApiModelProperty(value = "小票编号", name = "itemorderNo")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "小票编号不能为空")
    private String itemorderNo;
    /**
     * 取样车号
     */
    @Column(name = "car_no")
    @ApiModelProperty(value = "取样车号", name = "carNo")
    private String carNo;
    /**
     * 取样车牌
     */
    @Column(name = "car_card")
    @ApiModelProperty(value = "取样车牌", name = "carCard")
    private String carCard;
    /**
     * 样品状态
     */
    @Column(name = "sample_status")
    @ApiModelProperty(value = "样品状态", name = "sampleStatus")
    private String sampleStatus;
    /**
     * 代表数量
     */
    @Column(name = "stand_quantity")
    @ApiModelProperty(value = "代表数量", name = "standQuantity")
    private Double standQuantity;
    /**
     * 取样数量
     */
    @Column(name = "sample_quantity")
    @ApiModelProperty(value = "取样数量", name = "sampleQuantity")
    private Double sampleQuantity;
    /**
     * 司机名称
     */
    @Column(name = "driver_name")
    @ApiModelProperty(value = "司机名称", name = "driverName")
    private String driverName;
    /**
     * 司机电话
     */
    @Column(name = "driver_tel")
    @ApiModelProperty(value = "司机电话", name = "driverTel")
    private String driverTel;
    /**
     * 取样人id
     */
    @Column(name = "sample_person_id")
    @ApiModelProperty(value = "取样人id", name = "samplePersonId")
    private Long samplePersonId;
    /**
     * 取样人名称
     */
    @Column(name = "sample_person_name")
    @ApiModelProperty(value = "取样人名称", name = "samplePersonName")
    private String samplePersonName;
    /**
     * 取样时间
     */
    @Column(name = "sample_time")
    @ApiModelProperty(value = "取样时间", name = "sampleTime")
    private Date sampleTime;
    /**
     * 样品外观
     */
    @Column(name = "sample_appearance")
    @ApiModelProperty(value = "样品外观", name = "sampleAppearance")
    private String sampleAppearance;
    /**
     * 样品图片  多个用逗号隔开
     */
    @Column(name = "sample_img")
    @ApiModelProperty(value = "样品图片  多个用逗号隔开", name = "sampleImg")
    private String sampleImg;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    public ExperimentSampleTake init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setIsDel(0).setTakeNo(UidUtils.genNo(GenerateCodeEnum.EXPERIMENT_SAMPLE_TAKE.getCode()));
        }
        return this;
    }
}
